package com.lkd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lkd.base.BaseController;
import com.lkd.base.ResponseResult;
import com.lkd.domain.SkuClass;
import com.lkd.pageParam.SkuPageParam;
import com.lkd.service.SkuClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dev-api/skuClass")
@Api(tags = "商品类别管理")
public class SkuClassController extends BaseController {

    @Autowired
    private SkuClassService skuClassService;

    @PostMapping("/insert")
    @ApiOperation("新增商品类别")
    public ResponseResult insert(@RequestBody SkuClass skuClass) {
        skuClassService.save(skuClass);
        return success() ;
    }

    @PutMapping("/update")
    @ApiOperation("更新商品类别")
    public ResponseResult update(@RequestBody SkuClass skuClass) {
        skuClassService.updateById(skuClass);
        return success() ;
    }

    @DeleteMapping("/delete/{classId}")
    @ApiOperation("根据ID删除商品类别")
    public ResponseResult deleteById(@PathVariable @ApiParam(value = "类别ID", required = true) Integer classId) {
        skuClassService.getById(classId);
        return success();
    }

    @GetMapping("/{classId}")
    @ApiOperation("根据ID查询商品类别")
    public ResponseResult<SkuClass> selectById(@PathVariable @ApiParam(value = "类别ID", required = true) Integer classId) {
        return success(skuClassService.getById(classId));
    }
    @GetMapping
    @ApiOperation("根据类别名称查询商品类别信息")
    public ResponseResult<Page<SkuClass>> selectByClassName( SkuPageParam param) {

        return success(skuClassService.querySkuClassPage(param));
    }

    @GetMapping("/selectAll")
    @ApiOperation("查询所有商品类别")
    public ResponseResult<List<SkuClass>> selectAll() {

        List<SkuClass> list = skuClassService.list();
        return success(list);
    }
}